import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-03-01
 * Time: 16:05
 */
public class test1 {
    /**
     * LeetCode  946  验证栈序列
     */


    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> stack = new Stack<>();
        int i = 0;
        int n = popped.length;
        for(int x:pushed){
            stack.push(x);
            while(!stack.isEmpty() && stack.peek()==popped[i]){
                i++;
                stack.pop();
            }
        }
        return i==n;
    }
}
